﻿using System;
using System.Collections.Generic;
using System.Text;
using SharpSqlAnalyzer.scriptWriter;

namespace SharpSqlAnalyzer.nodes
{
	// Token: 0x02000330 RID: 816
	public abstract class TParseTreeNode : Visitable
	{
		// Token: 0x06001D38 RID: 7480 RVA: 0x00332D7C File Offset: 0x00330F7C
		public TParseTreeNode()
		{
		}

		// Token: 0x06001D39 RID: 7481 RVA: 0x00332DA2 File Offset: 0x00330FA2
		public TParseTreeNode(EDbVendor dbvendor)
		{
			this.dbvendor = dbvendor;
		}

		// Token: 0x06001D3A RID: 7482 RVA: 0x00332DCF File Offset: 0x00330FCF
		public bool IsIncludingOriginalTokens()
		{
			return this.startToken != null && this.endToken != null && this.startToken.container != null;
		}

		// Token: 0x06001D3B RID: 7483 RVA: 0x00332DF5 File Offset: 0x00330FF5
		public void setChanged()
		{
			if (this.startToken != null)
			{
				this.startToken.Changed = true;
			}
		}

		// Token: 0x06001D3C RID: 7484 RVA: 0x00332E0C File Offset: 0x0033100C
		public bool IsUnderlyingTokenChanged()
		{
			if (this.startToken == null)
			{
				return false;
			}
			if (this.endToken == null)
			{
				return false;
			}
			TSourceTokenList container = this.startToken.container;
			if (container == null)
			{
				return false;
			}
			int posinlist = this.startToken.posinlist;
			int posinlist2 = this.endToken.posinlist;
			for (int i = posinlist; i <= posinlist2; i++)
			{
				if (container.get(i).Changed)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x170006C8 RID: 1736
		// (get) Token: 0x06001D3D RID: 7485 RVA: 0x00332E71 File Offset: 0x00331071
		// (set) Token: 0x06001D3E RID: 7486 RVA: 0x00332E9A File Offset: 0x0033109A
		public virtual TGSharpSqlParser GSharpSqlParser
		{
			get
			{
				if (this.gSharpSqlParser == null && this.getStartToken() != null)
				{
					this.gSharpSqlParser = this.getStartToken().GSharpSqlParser;
				}
				return this.gSharpSqlParser;
			}
			set
			{
				this.gSharpSqlParser = value;
			}
		}

		// Token: 0x170006C9 RID: 1737
		// (set) Token: 0x06001D3F RID: 7487 RVA: 0x00332EA3 File Offset: 0x003310A3
		public virtual bool IncludingComment
		{
			set
			{
				this.includingComment = value;
			}
		}

		// Token: 0x170006CA RID: 1738
		// (get) Token: 0x06001D41 RID: 7489 RVA: 0x00332EB5 File Offset: 0x003310B5
		// (set) Token: 0x06001D40 RID: 7488 RVA: 0x00332EAC File Offset: 0x003310AC
		public virtual int DummyTag
		{
			get
			{
				return this._dummyTag;
			}
			set
			{
				this._dummyTag = value;
			}
		}

		// Token: 0x170006CB RID: 1739
		// (get) Token: 0x06001D42 RID: 7490 RVA: 0x00332EBD File Offset: 0x003310BD
		// (set) Token: 0x06001D43 RID: 7491 RVA: 0x00332EC5 File Offset: 0x003310C5
		public TSourceToken startToken
		{
			get
			{
				return this.getStartToken();
			}
			set
			{
				this._startToken = value;
			}
		}

		// Token: 0x06001D44 RID: 7492 RVA: 0x00332ECE File Offset: 0x003310CE
		public virtual TSourceToken getStartToken()
		{
			return this._startToken;
		}

		// Token: 0x06001D45 RID: 7493 RVA: 0x00332ED6 File Offset: 0x003310D6
		public virtual TSourceToken getEndToken()
		{
			return this._endToken;
		}

		// Token: 0x170006CC RID: 1740
		// (get) Token: 0x06001D46 RID: 7494 RVA: 0x00332EDE File Offset: 0x003310DE
		// (set) Token: 0x06001D47 RID: 7495 RVA: 0x00332EE6 File Offset: 0x003310E6
		public TSourceToken endToken
		{
			get
			{
				return this.getEndToken();
			}
			set
			{
				this._endToken = value;
			}
		}

		// Token: 0x170006CD RID: 1741
		// (get) Token: 0x06001D48 RID: 7496 RVA: 0x00332EEF File Offset: 0x003310EF
		public virtual long ColumnNo
		{
			get
			{
				if (this.getStartToken() != null)
				{
					this.columnNo = this.getStartToken().columnNo;
				}
				return this.columnNo;
			}
		}

		// Token: 0x170006CE RID: 1742
		// (get) Token: 0x06001D49 RID: 7497 RVA: 0x00332F10 File Offset: 0x00331110
		public virtual long LineNo
		{
			get
			{
				if (this.getStartToken() != null)
				{
					this.lineNo = this.getStartToken().lineNo;
				}
				return this.lineNo;
			}
		}

		// Token: 0x170006CF RID: 1743
		// (get) Token: 0x06001D4B RID: 7499 RVA: 0x00332F3A File Offset: 0x0033113A
		// (set) Token: 0x06001D4A RID: 7498 RVA: 0x00332F31 File Offset: 0x00331131
		public virtual int NodeType
		{
			get
			{
				return this.nodeType;
			}
			set
			{
				this.nodeType = value;
			}
		}

		// Token: 0x06001D4C RID: 7500 RVA: 0x00332F42 File Offset: 0x00331142
		internal virtual string getastext()
		{
			return "";
		}

		// Token: 0x06001D4D RID: 7501 RVA: 0x00332F49 File Offset: 0x00331149
		internal virtual string getasprettytext()
		{
			return "";
		}

		// Token: 0x06001D4E RID: 7502 RVA: 0x00332F50 File Offset: 0x00331150
		public virtual void init(object arg1)
		{
		}

		// Token: 0x06001D4F RID: 7503 RVA: 0x00332F52 File Offset: 0x00331152
		public virtual void init(object arg1, object arg2)
		{
		}

		// Token: 0x06001D50 RID: 7504 RVA: 0x00332F54 File Offset: 0x00331154
		public virtual void init(object arg1, object arg2, object arg3)
		{
		}

		// Token: 0x06001D51 RID: 7505 RVA: 0x00332F56 File Offset: 0x00331156
		public virtual void init(object arg1, object arg2, object arg3, object arg4)
		{
		}

		// Token: 0x06001D52 RID: 7506 RVA: 0x00332F58 File Offset: 0x00331158
		public virtual void init(object arg1, object arg2, object arg3, object arg4, object arg5)
		{
		}

		// Token: 0x06001D53 RID: 7507 RVA: 0x00332F5A File Offset: 0x0033115A
		public virtual void init(object arg1, object arg2, object arg3, object arg4, object arg5, object arg6)
		{
		}

		// Token: 0x06001D54 RID: 7508 RVA: 0x00332F5C File Offset: 0x0033115C
		public virtual void doParse(TCustomSqlStatement psql, ESqlClause plocation)
		{
		}

		// Token: 0x06001D55 RID: 7509 RVA: 0x00332F5E File Offset: 0x0033115E
		public virtual void setStartToken(TSourceToken startToken)
		{
			if (startToken == null)
			{
				return;
			}
			this.startToken = startToken;
			if (this.startToken != null)
			{
				this.startToken.nodesStartFromThisToken.Add(this);
			}
		}

		// Token: 0x06001D56 RID: 7510 RVA: 0x00332F84 File Offset: 0x00331184
		public virtual void setStartToken(TParseTreeNode startNode)
		{
			if (startNode == null)
			{
				return;
			}
			this.startToken = startNode.getStartToken();
			if (this.startToken != null)
			{
				this.startToken.nodesStartFromThisToken.Add(this);
			}
		}

		// Token: 0x06001D57 RID: 7511 RVA: 0x00332FB0 File Offset: 0x003311B0
		public virtual void setStartToken<T>(List<T> pList)
		{
			if (pList == null)
			{
				return;
			}
			TParseTreeNode tparseTreeNode = (TParseTreeNode)((object)pList[0]);
			this.startToken = tparseTreeNode.getStartToken();
			if (this.startToken != null)
			{
				this.startToken.nodesStartFromThisToken.Add(this);
			}
		}

		// Token: 0x06001D58 RID: 7512 RVA: 0x00332FF8 File Offset: 0x003311F8
		public virtual void setEndToken(TSourceToken endToken)
		{
			if (endToken == null)
			{
				return;
			}
			this.endToken = endToken;
			if (this.endToken != null)
			{
				this.endToken.nodesEndWithThisToken.Add(this);
			}
		}

		// Token: 0x06001D59 RID: 7513 RVA: 0x0033301E File Offset: 0x0033121E
		public virtual void setEndToken(TParseTreeNode endNode)
		{
			if (endNode == null)
			{
				return;
			}
			this.endToken = endNode.getEndToken();
			if (this.endToken != null)
			{
				this.endToken.nodesEndWithThisToken.Add(this);
			}
		}

		// Token: 0x06001D5A RID: 7514 RVA: 0x0033304C File Offset: 0x0033124C
		public virtual void setEndToken<T>(List<T> pList)
		{
			if (pList == null)
			{
				return;
			}
			TParseTreeNode tparseTreeNode = (TParseTreeNode)((object)pList[pList.Count - 1]);
			this.endToken = tparseTreeNode.getEndToken();
			if (this.endToken != null)
			{
				this.endToken.nodesEndWithThisToken.Add(this);
			}
		}

		// Token: 0x06001D5B RID: 7515 RVA: 0x0033309B File Offset: 0x0033129B
		private void setStartTokenToNull()
		{
			this.startToken = null;
		}

		// Token: 0x06001D5C RID: 7516 RVA: 0x003330A4 File Offset: 0x003312A4
		private void setEndTokenToNull()
		{
			this.endToken = null;
		}

		// Token: 0x06001D5D RID: 7517 RVA: 0x003330B0 File Offset: 0x003312B0
		private void resetStartAndEndTokenBeforeRemoveTokens(TSourceTokenList stList, int start, int end, bool isReplace, TSourceToken relpacedStartToken, TSourceToken replacedEndToken)
		{
			for (int i = start; i <= end; i++)
			{
				TSourceToken tsourceToken = stList.get(i);
				for (int j = 0; j < tsourceToken.nodesStartFromThisToken.Count; j++)
				{
					TParseTreeNode tparseTreeNode = tsourceToken.nodesStartFromThisToken[j];
					TSourceToken endToken = tparseTreeNode.getEndToken();
					if (isReplace && (i == start || i == end))
					{
						tparseTreeNode.setStartToken(relpacedStartToken);
					}
					else if (endToken == null)
					{
						tparseTreeNode.setStartTokenToNull();
					}
					else if (endToken.posinlist > end)
					{
						tparseTreeNode.setStartToken(stList.get(end + 1));
					}
					else if (endToken.posinlist < start)
					{
						tparseTreeNode.setStartTokenToNull();
						tparseTreeNode.setEndTokenToNull();
					}
					else
					{
						tparseTreeNode.setStartTokenToNull();
						tparseTreeNode.setEndTokenToNull();
					}
				}
				for (int k = 0; k < tsourceToken.nodesEndWithThisToken.Count; k++)
				{
					TParseTreeNode tparseTreeNode2 = tsourceToken.nodesEndWithThisToken[k];
					TSourceToken startToken = tparseTreeNode2.getStartToken();
					if (isReplace && (i == start || i == end))
					{
						tparseTreeNode2.setEndToken(replacedEndToken);
					}
					else if (startToken == null)
					{
						tparseTreeNode2.setEndTokenToNull();
					}
					else if (startToken.posinlist > end)
					{
						tparseTreeNode2.setStartTokenToNull();
						tparseTreeNode2.setEndTokenToNull();
					}
					else if (startToken.posinlist < start)
					{
						tparseTreeNode2.setEndToken(stList.get(start - 1));
					}
					else
					{
						tparseTreeNode2.setStartTokenToNull();
						tparseTreeNode2.setEndTokenToNull();
					}
				}
			}
		}

		// Token: 0x06001D5E RID: 7518 RVA: 0x00333208 File Offset: 0x00331408
		private EDbVendor FindFirstAvailableParser()
		{
			EDbVendor result = EDbVendor.dbvmssql;
			if (TCustomLexer.IsLexerIncluded("mssql"))
			{
				result = EDbVendor.dbvmssql;
			}
			else if (TCustomLexer.IsLexerIncluded("db2"))
			{
				result = EDbVendor.dbvdb2;
			}
			else if (TCustomLexer.IsLexerIncluded("greenplum"))
			{
				result = EDbVendor.dbvgreenplum;
			}
			else if (TCustomLexer.IsLexerIncluded("hive"))
			{
				result = EDbVendor.dbvhive;
			}
			else if (TCustomLexer.IsLexerIncluded("impala"))
			{
				result = EDbVendor.dbvimpala;
			}
			else if (TCustomLexer.IsLexerIncluded("informix"))
			{
				result = EDbVendor.dbvinformix;
			}
			else if (TCustomLexer.IsLexerIncluded("mdx"))
			{
				result = EDbVendor.dbvmdx;
			}
			else if (TCustomLexer.IsLexerIncluded("mysql"))
			{
				result = EDbVendor.dbvmysql;
			}
			else if (TCustomLexer.IsLexerIncluded("netezza"))
			{
				result = EDbVendor.dbvnetezza;
			}
			else if (TCustomLexer.IsLexerIncluded("oracle"))
			{
				result = EDbVendor.dbvoracle;
			}
			else if (TCustomLexer.IsLexerIncluded("postgresql"))
			{
				result = EDbVendor.dbvpostgresql;
			}
			else if (TCustomLexer.IsLexerIncluded("redshift"))
			{
				result = EDbVendor.dbvredshift;
			}
			else if (TCustomLexer.IsLexerIncluded("sybase"))
			{
				result = EDbVendor.dbvsybase;
			}
			else if (TCustomLexer.IsLexerIncluded("teradata"))
			{
				result = EDbVendor.dbvteradata;
			}
			return result;
		}

		// Token: 0x170006D0 RID: 1744
		// (get) Token: 0x06001D60 RID: 7520 RVA: 0x0033338E File Offset: 0x0033158E
		// (set) Token: 0x06001D5F RID: 7519 RVA: 0x00333314 File Offset: 0x00331514
		public virtual string String
		{
			get
			{
				if (this._stringValue != null)
				{
					return this._stringValue;
				}
				return this.ToString();
			}
			set
			{
				this._stringValue = value;
				this.SourceTokenList.clear();
				if (this.dbvendor == EDbVendor.dbvgeneric)
				{
					this.dbvendor = this.FindFirstAvailableParser();
				}
				TGSharpSqlParser tGSharpSqlParser = new TGSharpSqlParser(this.dbvendor);
				tGSharpSqlParser.sqltext = value;
				tGSharpSqlParser.tokenizeSqltext();
				for (int i = 0; i < tGSharpSqlParser.sourcetokenlist.size(); i++)
				{
					this.SourceTokenList.add(tGSharpSqlParser.sourcetokenlist.get(i));
				}
			}
		}

		// Token: 0x170006D1 RID: 1745
		// (get) Token: 0x06001D62 RID: 7522 RVA: 0x003333B0 File Offset: 0x003315B0
		// (set) Token: 0x06001D61 RID: 7521 RVA: 0x003333A5 File Offset: 0x003315A5
		public TSourceTokenList SourceTokenList
		{
			get
			{
				if (this._sourceTokenList == null)
				{
					this._sourceTokenList = new TSourceTokenList();
					TSourceToken startToken = this.getStartToken();
					TSourceToken endToken = this.getEndToken();
					TSourceTokenList tsourceTokenList = null;
					if (startToken != null)
					{
						tsourceTokenList = startToken.container;
					}
					if (startToken != null && endToken != null && tsourceTokenList != null)
					{
						int posinlist = startToken.posinlist;
						int posinlist2 = endToken.posinlist;
						for (int i = posinlist; i <= posinlist2; i++)
						{
							if (this.includingComment || (tsourceTokenList.get(i).tokencode != 257 && tsourceTokenList.get(i).tokencode != 258))
							{
								this._sourceTokenList.add(tsourceTokenList.get(i));
							}
						}
					}
				}
				return this._sourceTokenList;
			}
			set
			{
				this._sourceTokenList = value;
			}
		}

		// Token: 0x06001D63 RID: 7523 RVA: 0x0033345C File Offset: 0x0033165C
		public string ToString(bool isModified)
		{
			if (!isModified)
			{
				return this.ToString();
			}
			TSourceToken startToken = this.getStartToken();
			if (startToken == null)
			{
				return null;
			}
			TSourceToken endToken = this.getEndToken();
			if (endToken == null)
			{
				return null;
			}
			StringBuilder stringBuilder = new StringBuilder("");
			for (TSourceToken tsourceToken = startToken; tsourceToken != null; tsourceToken = tsourceToken.NextTokenInChain)
			{
				if (this.includingComment || (tsourceToken.tokencode != 257 && tsourceToken.tokencode != 258))
				{
					stringBuilder.Append(tsourceToken.ToString());
				}
				if (tsourceToken.Equals(endToken))
				{
					break;
				}
			}
			return stringBuilder.ToString();
		}

		// Token: 0x06001D64 RID: 7524 RVA: 0x003334E4 File Offset: 0x003316E4
		public override string ToString()
		{
			if (this.SourceTokenList.Count > 0)
			{
				StringBuilder stringBuilder = new StringBuilder("");
				for (int i = 0; i < this.SourceTokenList.Count; i++)
				{
					stringBuilder.Append(this.SourceTokenList.get(i).ToString());
				}
				return stringBuilder.ToString();
			}
			return null;
		}

		// Token: 0x06001D65 RID: 7525 RVA: 0x00333540 File Offset: 0x00331740
		public string ToScript()
		{
			if (this.scriptGenerator == null)
			{
				this.scriptGenerator = new TScriptGenerator();
			}
			return this.scriptGenerator.generateScript(this);
		}

		// Token: 0x06001D66 RID: 7526 RVA: 0x00333564 File Offset: 0x00331764
		public virtual int addAllMyTokensToTokenList(TSourceTokenList targetList, int index)
		{
			int result = -1;
			TSourceToken startToken = this.getStartToken();
			if (startToken == null)
			{
				return result;
			}
			TSourceToken endToken = this.getEndToken();
			if (endToken == null)
			{
				return result;
			}
			TSourceTokenList container = startToken.container;
			if (container == null)
			{
				return result;
			}
			for (int i = endToken.posinlist; i >= startToken.posinlist; i--)
			{
				targetList.add(index, container.get(i));
				container.get(i).container = targetList;
			}
			for (int j = index; j < targetList.size(); j++)
			{
				targetList.get(j).posinlist = j;
			}
			return endToken.posinlist - startToken.posinlist + 1;
		}

		// Token: 0x06001D67 RID: 7527 RVA: 0x00333601 File Offset: 0x00331801
		public virtual void accept(TParseTreeVisitor v)
		{
		}

		// Token: 0x06001D68 RID: 7528 RVA: 0x00333603 File Offset: 0x00331803
		public virtual void acceptChildren(TParseTreeVisitor v)
		{
		}

		// Token: 0x04001A9F RID: 6815
		public EDbVendor dbvendor = EDbVendor.dbvgeneric;

		// Token: 0x04001AA0 RID: 6816
		private TGSharpSqlParser gSharpSqlParser;

		// Token: 0x04001AA1 RID: 6817
		internal bool includingComment = true;

		// Token: 0x04001AA2 RID: 6818
		private int _dummyTag;

		// Token: 0x04001AA3 RID: 6819
		private TSourceToken _startToken;

		// Token: 0x04001AA4 RID: 6820
		private TSourceToken _endToken;

		// Token: 0x04001AA5 RID: 6821
		private long lineNo = -1L;

		// Token: 0x04001AA6 RID: 6822
		private long columnNo = -1L;

		// Token: 0x04001AA7 RID: 6823
		private int nodeType;

		// Token: 0x04001AA8 RID: 6824
		protected string _stringValue;

		// Token: 0x04001AA9 RID: 6825
		private TSourceTokenList _sourceTokenList;

		// Token: 0x04001AAA RID: 6826
		private TScriptGenerator scriptGenerator;
	}
}
